package org.example.aienglishapp.controller.loginlog;

import org.example.aienglishapp.entity.loginlog.LoginLog;
import org.example.aienglishapp.service.loginlog.LoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class LoginLogController {

    @Autowired
    private LoginLogService loginLogService;

    // Get all login logs
    @GetMapping("/loginlog/all")
    public ResponseEntity<List<LoginLog>> getAllLoginLogs() {
        List<LoginLog> logs = loginLogService.getAllLoginLogs();
        if (logs.isEmpty()) {
            return ResponseEntity.noContent().build();
        }
        return ResponseEntity.ok(logs);
    }

    // delete login log by id
    @DeleteMapping("/loginlog/delete/{info_id}")
    public ResponseEntity<Void> deleteLoginLog(@PathVariable Long info_id) {
        loginLogService.deleteLoginLog(info_id);
        return ResponseEntity.noContent().build();
    }
}
